home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 June / PCWorld_2002-06_cd.bin / Software / TemaCD / arachno / Arachnophilia.exe / {app} / Arachnophilia.jar / CustomClasses / TestClass.java < prev   
Encoding:
Java Source  |  2002-03-08  |  1.8 KB  |  62 lines

  1. /*
  2.  *        Created on Mar 8, 2002 9:18:55 PM
  3.  */
  4.  
  5. /* TestClass is meant to demonstrate the use
  6.  * of Arachnophilia's custom class launcher feature.
  7.  * Just compile this class in place, create
  8.  * a macro that looks like this:
  9.  * "[RunCustomClassDoc:CustomClasses/TestClass]",
  10.  * load a suitable document, and activate the macro.
  11.  */
  12.  
  13. import java.util.*;
  14.  
  15. public class TestClass {
  16.    
  17.    // this is a generic, minimal global search & replace method
  18.    
  19.    private String searchReplace(String data,String find,String replace)
  20.    {
  21.       StringBuffer sb = new StringBuffer();
  22.       int a = 0,b;
  23.       int findLength = find.length();
  24.       while((b = data.indexOf(find,a)) != -1) {
  25.          sb.append(data.substring(a,b));
  26.          sb.append(replace);
  27.          a = b + findLength;
  28.       }
  29.       if(a < data.length()) {
  30.          sb.append(data.substring(a));
  31.       }
  32.       return sb.toString();
  33.    }
  34.    
  35.    // this is the default method that custom classes
  36.    // must have to work with Arachnophilia's class
  37.    // launcher feature unless a specific method name
  38.    // is provided
  39.    
  40.    public String processString(String s)
  41.    {
  42.       String result = "Hello! This is an example of Java Custom Class Interfacing!\n\n"
  43.       + "You sent over this:\n"
  44.       + "\"" + s + "\"\n"
  45.       + "Here it is all uppercase:\n"
  46.       + "\"" + s.toUpperCase() + "\"\n"
  47.       + "Here it is all lowercase:\n"
  48.       + "\"" + s.toLowerCase() + "\"\n"
  49.       + "Here it is with a global change:\n"
  50.       + "\"" + searchReplace(s,"a","(A)") + "\"\n";
  51.       return result;
  52.    }
  53.    
  54.    // this is another method to show the ability to choose
  55.    // any method by name
  56.    
  57.    public String reallyBoringMethod(String s)
  58.    {
  59.       return "On " + new Date() + ", you invoked this really boring Java method.";
  60.    }
  61. }
  62.